package chap_07;

import org.junit.jupiter.api.Test;

import java.util.stream.IntStream;
import java.util.stream.StreamSupport;

public class Run_03 {

    @Test
    public void test01() {
        String s = " Nel mezzo del cammin di nostra vita mi ritrovai in una selva oscura ché la dritta via era smarrita ";
        WordCounter wordCounter = IntStream.range(0, s.length())
                .mapToObj(s::charAt)
                .reduce(new WordCounter(0, true),
                        WordCounter::accumulate,
                        WordCounter::combine);

        System.out.println(wordCounter.getCounter());
    }

    @Test
    public void test02() {
        String s = " Nel mezzo del cammin di nostra vita mi ritrovai in una selva oscura ché la dritta via era smarrita ";
        WordCounterSpliterator spliterator = new WordCounterSpliterator(s);
        long count = StreamSupport.stream(spliterator, true).count();
        System.out.println(count);

        StreamSupport.stream(spliterator, true);
    }
}
